import { FindLimitDto, type FindList } from "./auth";

export enum StatusContent {
  Publish = "publish",
  Draft = "draft",
}

export const statusOptions: {
  label: string;
  value: string;
}[] = [
  { label: "发布", value: StatusContent.Publish },
  { label: "草稿", value: StatusContent.Draft },
];
export interface page {
  id: string; // 标记为主列，值自动生成
  name: string;
  path: string;
  isCommentOpen: boolean;
  content: string;
  contentHtml: string;
  status?: StatusContent;
  order?: number;
  views?: number;
  publishTime: Date;
  createTime: Date;
  updateTime: Date;
}

export class QueryPageDto extends FindLimitDto {
  status?: StatusContent | null;
  name?: string;
  path?: string;
}

export interface createPage {
  name: string;
  path: string;
  isCommentOpen: boolean;
  content: string;
  contentHtml: string;
  status?: StatusContent;
  order?: number;
}

export interface updatePage {
  name?: string;
  path?: string;
  isCommentOpen?: boolean;
  content?: string;
  contentHtml: string;
  status?: StatusContent;
  order?: number;
}

export const findAllPages = (query?: QueryPageDto) => {
  return useServerRequest<page[]>("/page/findAllPages", {
    method: "GET",
    query: { ...query },
  });
};

export const findOneById = (id: string) => {
  return useServerRequest<page>(`/page/${id}`, {
    method: "GET",
  });
};

export const findViewsByPath = (path: string) => {
  return useServerRequest<page>(`/page/findViewsByPath/${path}`, {
    method: "GET",
  });
};
